package com.yanqu.road.server.logic.bag;

import com.yanqu.road.entity.bag.UseGoodsResult;
import com.yanqu.road.entity.config.goods.GoodsInfo;
import com.yanqu.road.entity.config.goods.OpenGoodsBagResult;
import com.yanqu.road.entity.enums.eLogMoneyType;
import com.yanqu.road.entity.enums.eMessageType;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.player.CurrencyModule;
import com.yanqu.road.server.manger.config.GoodsBagMgr;
import com.yanqu.road.server.manger.player.WorldMessageMgr;
import com.yanqu.road.utils.property.Property;
import com.yanqu.road.utils.property.PropertyHelper;

import java.math.BigInteger;

public class UseWasheSkillBag extends BaseUseGoods {
    public UseWasheSkillBag(GamePlayer player, GoodsInfo goodsInfo, long param) {
        super(player, goodsInfo, param);
    }

    @Override
    int checkUse(long count) {
        return 0;
    }

    @Override
    UseGoodsResult executeUse(long count) {
        UseGoodsResult result = new UseGoodsResult();
        Property reward = new Property();
        for (long i = 0; i < count; i++) {
            int openTime = goodsInfo.getParamList().get(1).intValue();
            if (openTime >0){
                for (int z = 0;z < openTime;z++){
                    OpenGoodsBagResult openResult = GoodsBagMgr.getRandomGoods(goodsInfo.getGoodsId());
                    reward.addProperty(openResult.getReward());
                    if(openResult.getNotice() == 1){
                        WorldMessageMgr.worldNotify(player, eMessageType.OpenGoodsBagNotice.getValue(), player.getUserInfo().getCity(), player.getTitleId(),
                                player.getUserInfo().getNickName(), goodsInfo.getGoodsId(), PropertyHelper.parsePropertyToString(openResult.getReward()));
                    }
                }
            }
        }
        player.getModule(CurrencyModule.class).addCurrency(reward, eLogMoneyType.Bag, eLogMoneyType.OpenGoodsBag);
        result.setReward(PropertyHelper.parsePropertyToString(reward));
        return result;
    }
}
